package com.lagou.edu.course.controller;

import com.lagou.edu.dto.CourseDTO;
import com.lagou.edu.remote.CourseRemoteService;
import com.lagou.edu.response.ResponseDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/course")
public class CourseController {

    @Autowired
    private CourseRemoteService courseRemoteService;

    @PostMapping("/swithOnlineStatus")
    public ResponseDTO switchOnlineStatus(@RequestBody CourseDTO courseDTO) throws Exception {
        System.out.println(">>>>hhhh: " + courseDTO.getId() + " status: " + courseDTO.getStatus());
        ResponseDTO responseDTO = courseRemoteService.switchOnlineStatus(courseDTO);
        return responseDTO;
    }

    @PostMapping("/saveOrUpdate")
    public ResponseDTO saveOrUpdate(@RequestBody CourseDTO courseDTO) {
        return courseRemoteService.saveOrUpdateCourse(courseDTO);
    }

    @GetMapping("/getAllCourses")
    public ResponseDTO<List<CourseDTO>> getAllCourses() throws Exception{
        List<CourseDTO> courseList = courseRemoteService.getAllCourses();
        return ResponseDTO.success(courseList);
    }
}
